<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;

class CardRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 新增
     * @return array
     */
    public function rules()
    {
        return [
            'category_id' => 'required|integer',
            'card_question' => 'required|string|max:100',
            'card_answer' => 'required_without:image_url|string|max:255',
            'image_url' => 'required_without:card_answer|string|max:255|regex:/^tmp\/.+\./i'
        ];
    }

    public function messages()
    {
        return [
            'category_id.required' => '请选择笔记本',
            'category_id.integer' => '请选择笔记本',
            'card_question.required' => '请输入问题',
            'card_question.max' => '问题最多不能超过100字',
            'card_answer.required_without' => '请至少填写以下一项内容：图片或答案',
            'card_answer.max' => '答案最多255字',
            'image_url.required_without' => '请至少填写以下一项内容：图片或答案',
            'image_url.max' => '图片地址长度超出限制',
            'image_url.regex' => '图片格式不正确'
        ];
    }
}
